# 52. 字符串分割转换

52

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

let lines = [];
rl.on('line', function(line) {
    lines.push(line);
    if (lines.length === 2) {
        const k = parseInt(lines[0]);
        const s = lines[1];
        const arr = s.split('-');
        const prefix = arr.shift();
        const postfix = arr.join('');
        let n = '';
        let reArr = [];
        for(let i=0; i<postfix.length; i++) {
            n += postfix[i];
            if (n.length === k || i === postfix.length - 1 && n) {
                reArr.push(n);
                n = '';
            }
        }
        const ans = reArr.map(item => {
            let upper = 0;
            let lower = 0;
            for(let i=0; i< item.length; i++) {
                if (/[a-z]/.test(item[i])) lower++;
                if (/[A-Z]/.test(item[i])) upper++;
            }
            if (upper > lower) {
                return item.toUpperCase();
            }
            if (lower > upper) {
                return item.toLowerCase();
            }
            return item;
        });
        console.log(prefix + '-' + ans.join('-'))
    }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42